package com.glut.forum.config;

import com.glut.forum.interceptors.JWTInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * @author milo
 * @since 2021/9/2 下午8:04
 * @version 1.0
 */
@Configuration
public class SpringMvcConfig implements WebMvcConfigurer {

    // 配置拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new JWTInterceptor())
                .addPathPatterns("/forum/**")
                .addPathPatterns("forum/article/save")
                .excludePathPatterns("/forum/user/login")
                .excludePathPatterns("/forum/user/save")
                .excludePathPatterns("/forum/user/status/**")
                .excludePathPatterns("/forum/user/pwd/forget")
                .excludePathPatterns("/forum/user/pwd/update/email")
                .excludePathPatterns("/forum/article/**");
    }

    // 内容协商
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers){
        //注册@CurrentUser注解的实现类
        argumentResolvers.add(new CurrentUserIdHandlerMethodArgResolver());
    }

}
